﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NewstorePlateformeDAO;

namespace NewstorePlateformeApp.Controllers
{ 
    public class ADM_PickingController : Controller
    {
        private Newstore_PL_GOLD_BDDEntities db = new Newstore_PL_GOLD_BDDEntities();

        //
        // GET: /ADM_Picking/

        public ViewResult Index()
        {
            var picking = db.Picking.Include("Lieux");
            return View(picking.ToList());
        }

        //
        // GET: /ADM_Picking/Details/5

        public ViewResult Details(int id)
        {
            Picking picking = db.Picking.Single(p => p.idLieux == id);
            return View(picking);
        }

        //
        // GET: /ADM_Picking/Create

        public ActionResult Create()
        {
            ViewBag.idLieux = new SelectList(db.Lieux, "idLieux", "codeLieu");
            return View();
        } 

        //
        // POST: /ADM_Picking/Create

        [HttpPost]
        public ActionResult Create(Picking picking)
        {
            if (ModelState.IsValid)
            {
                db.Picking.AddObject(picking);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.idLieux = new SelectList(db.Lieux, "idLieux", "codeLieu", picking.idLieux);
            return View(picking);
        }
        
        //
        // GET: /ADM_Picking/Edit/5
 
        public ActionResult Edit(int id)
        {
            Picking picking = db.Picking.Single(p => p.idLieux == id);
            ViewBag.idLieux = new SelectList(db.Lieux, "idLieux", "codeLieu", picking.idLieux);
            return View(picking);
        }

        //
        // POST: /ADM_Picking/Edit/5

        [HttpPost]
        public ActionResult Edit(Picking picking)
        {
            if (ModelState.IsValid)
            {
                db.Picking.Attach(picking);
                db.ObjectStateManager.ChangeObjectState(picking, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.idLieux = new SelectList(db.Lieux, "idLieux", "codeLieu", picking.idLieux);
            return View(picking);
        }

        //
        // GET: /ADM_Picking/Delete/5
 
        public ActionResult Delete(int id)
        {
            Picking picking = db.Picking.Single(p => p.idLieux == id);
            return View(picking);
        }

        //
        // POST: /ADM_Picking/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Picking picking = db.Picking.Single(p => p.idLieux == id);
            db.Picking.DeleteObject(picking);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}